package nettypro.nio;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @ClassName NIOFileChannel01
 * @Description TODO
 * @Author zeny
 * @Date 2020/3/21 0021 21:33
 */
public class NIOFileChannel01 {
    public static void main(String[] args) throws IOException {
        String str = "hello, 尚硅谷";
        FileOutputStream fileOutputStream = new FileOutputStream("E:\\project\\datastructures\\demo.txt");
        FileChannel channel = fileOutputStream.getChannel();
        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
        byteBuffer.put(str.getBytes());
        byteBuffer.flip();
        channel.write(byteBuffer);
        fileOutputStream.close();
    }
}
